package com.ruoyi.app.zzq.controller;

import com.ruoyi.app.zzq.domain.User;
import com.ruoyi.app.zzq.service.InforService;
import com.ruoyi.app.zzq.service.MigrateService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/migrate")
public class MigrateController  extends BaseController {
    @Autowired
    private MigrateService migrateService;
    @Autowired
    InforService inforService;

    @ApiOperation("查看服务队详细信息功能")
    @GetMapping(value = "/selectteam")
    public AjaxResult SelectServerByid(String id)
    {
        return AjaxResult.success(migrateService.SelectServerByid(id));
    }

    @ApiOperation("查看我的服务队功能")
    @GetMapping(value = "/selectmyservers")
    public AjaxResult SelectMyServerByid()
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        User u1=inforService.SelectUserById(""+userId);
        System.out.println(u1);
        if(u1.getTeamId().equals(""))
        {
            return AjaxResult.success("未加入服务队");
        }
        System.out.println(migrateService.SelectMyServerByid(u1.getTeamId()));
        return AjaxResult.success(migrateService.SelectMyServerByid(u1.getTeamId()));
//        return AjaxResult.success(migrateService.SelectMyServerByid("1,3"));
    }

    @ApiOperation("查看服务队队长与队员功能")
    @GetMapping(value = "/selectmember")
    public AjaxResult SelectServermember(String teamid)
    {
        return AjaxResult.success(migrateService.SelectServermember(teamid));
    }

    @ApiOperation("申请解散服务队功能")
    @GetMapping(value = "/missteam")
    public AjaxResult DisbandServerTeam(String teamid)
    {
        return AjaxResult.success(migrateService.DisbandServerTeam(teamid));
    }

    @ApiOperation("队长转移功能")
    @GetMapping(value = "/divert")
    public AjaxResult ServerCaptainTransfer(String teamid,String userid,String captain)
    {
        return AjaxResult.success(migrateService.ServerCaptainTransfer(teamid,userid,captain));
    }
    @ApiOperation("判断是否加入服务队")
    @GetMapping(value = "/isjoin")
    public AjaxResult Isjoin(String teamid)

    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.Isjoin(teamid,""+userId));
    }
    @ApiOperation("加入服务队")
    @GetMapping(value = "/joinServer")
    public AjaxResult joinServer(String teamid)
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.joinServer(teamid,""+userId));
    }
    @ApiOperation("退出服务队")
    @GetMapping(value = "/outServer")
    public AjaxResult outServer(String teamid)
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.outServer(teamid,""+userId));
    }
    @ApiOperation("查看是否加入暖心团")
    @GetMapping(value = "/isjoinHeart")
    public AjaxResult IsjoinHeart()
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.IsjoinHeart(""+userId));
    }
    @ApiOperation("加入暖心团")
    @GetMapping(value = "/joinHeart")
    public AjaxResult joinHeart()
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.joinHeart(""+userId));
    }
    @ApiOperation("退出暖心团")
    @GetMapping(value = "/outHeart")
    public AjaxResult outHeart()
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.outHeart(""+userId));
    }
    @ApiOperation("根据关键词获取服务队信息")
    @GetMapping(value = "/selectServerBykey")
    public AjaxResult SelectServerBykey(String key)
    {
        return AjaxResult.success(migrateService.SelectServerBykey(key));
    }
    @ApiOperation("获取是否为团队领导人")
    @GetMapping(value = "/isteamleader")
    public AjaxResult isTeamLeader(String teamid)
    {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        return AjaxResult.success(migrateService.isTeamLeader(teamid,userId+""));
    }
    @ApiOperation("解散团队")
    @GetMapping(value = "/killteam")
    public AjaxResult KillServer(String teamid)
    {
        return AjaxResult.success(migrateService.KillTeam(teamid));
    }
    @ApiOperation("获取暖心团成员")
    @GetMapping(value = "/getHeartMember")
    public AjaxResult getHeartMember(String teamid)
    {
        return AjaxResult.success(migrateService.getHeartMember(teamid));
    }

}
